package com.vken.blog.action;

import com.opensymphony.xwork2.ActionSupport;
import com.vken.blog.service.BlogManager;
import com.vken.blog.service.CommentManager;
import com.vken.blog.util.Const;
import com.vken.blog.util.Pagination;

public class CommentAction extends ActionSupport {
	private static final long serialVersionUID = 6883338947979477783L;
	private CommentManager commentManager;
	private BlogManager blogManager;
	private Integer[] commentId;
	private Integer p;
	private Pagination pagination;
	private String m;

	public void setCommentManager(CommentManager commentManager) {
		this.commentManager = commentManager;
	}

	public void setBlogManager(BlogManager blogManager) {
		this.blogManager = blogManager;
	}

	public void setCommentId(Integer[] commentId) {
		this.commentId = commentId;
	}

	public BlogManager getBlogManager() {
		return blogManager;
	}

	public void setM(String m) {
		this.m = m;
	}

	public void setP(Integer p) {
		this.p = p;
	}

	public Pagination getPagination() {
		return pagination;
	}

	public void setPagination(Pagination pagination) {
		this.pagination = pagination;
	}

	public String list() {
		if (p == null || p <= 0) {
			p = new Integer(1);
		}
		Integer pageSize = blogManager.get(Const.BLOG_ID).getBackendPageSize();
		pagination = commentManager.getListByBlogId(Const.BLOG_ID, null, pageSize, p);
		return SUCCESS;
	}

	public String updateOrDelete() {
		if (commentId != null && m != null && m.equals("update")) {
			commentManager.updateComments(commentId);
		} else if (m != null && commentId != null && m.equals("delete")) {
			commentManager.deleteComments(commentId);
		}
		return SUCCESS;
	}
}
